package com.itheima.health.service.impl;

import com.itheima.health.dao.MemberDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author: liangWeiQUQ
 * @Description: TODO
 * @DateTime: 2021/3/5 14:57
 **/
@DubboService
@Slf4j
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao ;


    /**
       * @Author: 传闻中的梁大侠
       * @Date: 15:00 2021/3/5
       * @Parms [member]
       * @ReturnType: com.itheima.health.pojo.Member
       * @Description: 用户提交预约后，如果没有用户信息就创建，有用户信息就实现信息的更新
                        * 根据手机号查询
     */
    @Override
    public Member addIfNotExist(Member member) {
        //先查询用户是否存在
        Member member1 = new Member();
        member1.setPhoneNumber(member.getPhoneNumber());
        Member one = memberDao.selectOne(member1);
        if (null == one) {//如果不存在，则创建这个用户并且添加
            memberDao.insertSelective(member);
        } else {//存在，则更新这个用户的信息
            member.setId(one.getId());
            memberDao.updateByPrimaryKeySelective(member);
        }
        return member;
    }
}
